import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import DefineOptions from 'unplugin-vue-define-options/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import globImport from 'vite-plugin-glob-import'
// rewrite: (path) => path.replace(/^\//, '')
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  server: {
    host: '0.0.0.0',
    port: 5173,
    open: true,
    proxy: {
      '/portal': {
        target: 'http://localhost:9001',
        changeOrigin: true
      }
    }
  },
  build: {
    // 打包别名
    outDir: 'dist'
  },
  plugins: [
    vue(),
    DefineOptions(),
    vueDevTools(),
    // 自动导入组件
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  //配置css变量
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
